package com.wink.dt;

import java.util.ArrayList;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.google.gson.Gson;
import com.wink.charity.Charity;
import com.wink.common.Identity;

@XmlRootElement(name = "topic")
@XmlAccessorType(XmlAccessType.FIELD)
public class Topic  {	
	
	@XmlElement(name = "topictitle")
	private String topictitle;
	
	@XmlElement(name = "topicdescription")
	private String topicdescription;	

	@XmlElement(name = "identity")
	private Identity identity;	
	
	ArrayList<Comment> data = new ArrayList<Comment>();	
	
	public String getTopicTitle() {
		return topictitle;
	}

	public void setTopicTitle(String topictitle) {
		this.topictitle = topictitle;
	}		

	public String getTopicdescription() {
		return topicdescription;
	}

	public void setTopicdescription(String topicdescription) {
		this.topicdescription = topicdescription;
	}
	
	public Identity getIdentity() {
		return identity;
	}

	public void setIdentity(Identity identity) {
		this.identity = identity;
	}
	
	public ArrayList<Comment> getCommentList() {
		return data;
	}
	
	public void addToCommentList(Comment comment) {
		data.add(comment);
	}
	
	public String toString() {
		StringBuffer sf = new StringBuffer();		

		sf.append("<topictitle> " + topictitle);
		sf.append("<topicdescription> " + topicdescription);
		sf.append("<identity> " + identity.toString());
				
		return sf.toString();
	}
	
	public static String toJson(Topic charity) {
		Gson gson = new Gson();
		String json = gson.toJson(charity, Topic.class);
		System.out.println("---> Topic: tojson  " + json);
		
		Topic retCh = gson.fromJson(json, Topic.class);
		return json;
	}
	
	public static Topic fromJson(String json) {
		Gson gson = new Gson();
		System.out.println("Reached ---> Topic: fromJson" + json);
		Topic retCh = gson.fromJson(json, Topic.class);
		System.out.println("---> Topic: fromJson  " + retCh.toString());
		return retCh;
	}
	
}
